// by Xeno
//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "tyr_repair\fn_trigger.sqf"
#include <core_macros.h>

TRACE_1("Start",_this);
TMFPROFILERSTART;

private ["_objs","_result"];
_result = false;
GVAR(Target_Vec) = objNull;
GVAR(Target_CanAnalyze) = false;
GVAR(Target_CanRepair) = false;
if (vehicle player == player && alive player) then {
	_objs = nearestObjects [player, ["LandVehicle","Air"], 7];
	if (count _objs > 0) then { GVAR(Target_Vec) = _objs select 0; };
	if (alive GVAR(Target_Vec)) then {
		GVAR(Target_CanAnalyze) = (damage GVAR(Target_Vec) > GVAR(min_damage) || !canMove GVAR(Target_Vec));
		GVAR(Target_CanRepair) = (damage GVAR(Target_Vec) < GVAR(max_damage)) && damage GVAR(Target_Vec) > GVAR(min_damage) && ("ToolKit" in (items player) || {{"ToolKit" == _x} count (itemCargo GVAR(Target_Vec)) > 0} || {count (nearestObjects[player,GVAR(RepairVehicleList),10]) > 0});
	};
};
_result = GVAR(Target_CanAnalyze) || GVAR(Target_CanRepair);
TRACE_1("End",_result);
TMFPROFILERSTOP;
_result 